(define (sum term a next b)
    (if (> a b)
        0
        (+ (term a)
           (sum term (next a) next b))))

(define (simpson-sum f a b n)
    (define (h a b n) (/ (- b a) n))
    (define (simpson-next x h) (+ x h))
    (define (simpson-term f x)
        (simpson-term2 f x 1))
    (define (simpson-term2 f x even?)
        (if (= even? 1)
        (* 2 (f x))
        (* 4 (f x))))
    (/ (* h
          (- (sum simpson-term a simpson-next b)
             (f a)
             (f b))) 3))

(define (cube x) (* x x x))
